package com.cuit.qx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cuit.qx.bean.Handover;
import com.cuit.qx.bean.WeatherStation;
import com.cuit.qx.dao.HandoverMapper;
import com.cuit.qx.service.HandoverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lcj
 * @since 2021-01-22
 */
@Service
public class HandoverServiceImpl extends ServiceImpl<HandoverMapper, Handover> implements HandoverService {

    @Autowired
    private HandoverMapper handoverMapper;

    @Override
    public List<Handover> getNewHandoverList(Integer pageNo, Integer pageSize, String name, String startTime, String endTime) {
        return handoverMapper.getNewHandover(pageNo, pageSize, name, startTime, endTime);
    }

    @Override
    public int getCount(String name, String startTime, String endTime) {
        return handoverMapper.getCounts(name, startTime, endTime);
    }

    @Override
    public Handover getNewHandover(String id) {
        return handoverMapper.selectById(id);
    }

    @Override
    public int updateNewHandover(String id) {
        return handoverMapper.updateNewHandoverById(id);
    }

    /**
     * 添加交班记录
     * @param handover
     * @return
     */
    @Override
    public Boolean addHandover(Handover handover) {
        //状态设为0
        handover.setStatus(0);
        int insert = handoverMapper.insert(handover);
        return insert == 1;
    }

    /**
     * 查询历史交接记录
     * @return
     */
    @Override
    public List<Handover> getHisList() {
        QueryWrapper<Handover> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",1);
        queryWrapper.orderByAsc("handover_time");
        List<Handover> list = handoverMapper.selectList(queryWrapper);
        return list;
    }

    /**
     * 修改历史交班记录
     * @param handover
     * @return
     */
    @Override
    public Boolean updateHisById(Handover handover) {
        int update = handoverMapper.updateById(handover);
        return update==1;
    }

}
